<?php


use Phinx\Db\Adapter\MysqlAdapter;
use Phinx\Migration\AbstractMigration;

class CreateReviewWorkflowTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('review_workflow', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => "审批配置表"]);

        //添加数据字段
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '审核流ID'])
            ->addColumn('active', 'enum', ['values' => 'yes,no', 'default' => 'yes', 'comment' => '审核流激活状态'])
            ->addColumn('type', 'enum', ['values' => 'step_task,outsource_task', 'default' => 'step_task', 'comment' => '审核流类型'])
            ->addColumn('execute_method', 'enum', ['values' => 'auto,manual', 'default' => 'auto', 'comment' => '审核流执行方式'])
            ->addColumn('name', 'string', ['null' => false, 'default' => '', 'limit' => 255, 'comment' => '审核流名称'])
            ->addColumn('description', 'text', ['null' => true, 'limit' => MysqlAdapter::TEXT_REGULAR, 'comment' => '审核流描述'])
            ->addColumn('is_deleted', 'enum', ['values' => 'yes,no', 'default' => 'no', 'comment' => '是否删除'])
            ->addColumn('created', 'integer', ['signed' => false, 'default' => 0, 'comment' => '创建时间', 'null' => false])
            ->addColumn('updated', 'integer', ['signed' => false, 'default' => 0, 'comment' => '更新时间', 'null' => false])
            ->addColumn('config', 'json', ['null' => true, 'comment' => 'json字段，存储自定义字段'])
            ->addColumn('uuid', 'char', ['default' => '', 'limit' => 36, 'comment' => '全局唯一标识符']);

        //执行创建
        $table->create();
    }
}
